<?php
namespace  app\miniapp\model;

use app\common\model\BaseCache;
use think\Model;
use XznsTools\cache\CacheManage;

class MiniVersion extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.mini_version';
    protected $cacheModelTT = 'miniapp.tt_hint_and_title';
    protected $cacheModelWeapp = 'miniapp.weapp_btn_desc';


    /**
     * 缓存获取TT小程序首页title&hint缓存
     * @param array $where
     * @param array $filed
     * @return array|bool|mixed
     * @throws \Exception
     */
    public function getMiniAppTtHintInfo(array $where = [], array $filed = [])
    {
        return CacheManage::getInstance()->setCacheConfig($this->cacheModelTT,$where['version_id'])->getDataAndSet(function () use ($where)
        {
            return $this->getMiniAppTtHintInfoFromDms($where);
        }, $filed);
    }

    /**
     * 数据库获取TT小程序首页title&hint缓存
     * @param array $where
     * @return array|mixed
     */
    public function getMiniAppTtHintInfoFromDms(array $where)
    {
        try
        {
            $data = $this->where($where)->field('tt_hint,tt_goods_desc')->findOrFail()->toArray();
            json_decode(json_encode($data,true),true);
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }



    /**
     * 缓存获取微信小程序btn信息缓存
     * @param array $where
     * @param array $filed
     * @return array|bool|mixed
     * @throws \Exception
     */
    public function getMiniAppBtnInfo(array $where = [], array $filed = [])
    {
       $data = CacheManage::getInstance()->setCacheConfig($this->cacheModelWeapp,$where['version_id'])->getDataAndSet(function () use ($where)
        {
            return $data = $this->getMiniAppBtnInfoDms($where);
        });
       return $data;
    }

    /**
     * 数据库获取微信小程序btn信息缓存
     * @param array $where
     * @return array|mixed
     */
    public function getMiniAppBtnInfoDms(array $where)
    {
        try
        {
            $data = $this->where($where)->field('weapp_btn_desc')->findOrFail()->toArray();
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }
}